// @ts-ignore
/* eslint-disable */
import { request } from 'umi';
import { encrypt } from '@/utils/encrypt';

const PROJECT_NAME = process.env.PROJECT_NAME;

/** 登录接口 */
export async function login(data: any) {
  // 首先获取公钥
  const result = await request(`/${PROJECT_NAME}/getPublicKey`, { method: 'POST' });
  const publicKey = result.msg;
  const enData = encrypt(JSON.stringify(data), publicKey);
  const params = {
    jsonData: enData,
    publicKey
  };
  return request(`/${PROJECT_NAME}/login_encrypted`, { method: 'POST', data: params });
}

/** 退出登录接口 */
export async function outLogin(data: any) {
  return request(`/${PROJECT_NAME}/logout`, { method: 'POST', data });
}

/** 发送验证码 */
export async function sendYzm(data: any) {
  return request(`/${PROJECT_NAME}/sendYzm`, { method: 'POST', data });
}

/** 账号密码登录 */
export async function loginMobilePhoneEncrypted(data: any) {

  // 首先获取公钥
  const result = await request(`/${PROJECT_NAME}/getPublicKey`, { method: 'POST' });
  const publicKey = result.msg;
  const enData = encrypt(JSON.stringify(data), publicKey);
  const params = {
    jsonData: enData,
    publicKey
  };

  return request(`/${PROJECT_NAME}/loginMobilePhoneEncrypted`, { method: 'POST', data: params });
}

/** 发送忘记密码验证码 */
export async function sendModifyYzm(data: any) {
  return request(`/${PROJECT_NAME}/sendModifyYzm?mobilePhone=${data.mobile}`, { method: 'POST', data });
}

/** 忘记密码 */
export async function forgetPwd(data: any) {

  // 首先获取公钥
  const result = await request(`/${PROJECT_NAME}/getPublicKey`, { method: 'POST' });
  const publicKey = result.msg;
  const enData = encrypt(JSON.stringify(data), publicKey);
  const params = {
    jsonData: enData,
    publicKey
  };

  return request(`/${PROJECT_NAME}/forgetPwd_encrypted`, { method: 'POST', data: params });
}

/** 修改密码 */
export async function updatePwd(data: any) {
  return request(`/${PROJECT_NAME}/sys/sysuser/updatePwd`, { method: 'POST', data });
}

/** 获取二维码 */
export async function getQrCode(data: any) {
  return request(`/${PROJECT_NAME}/login/getQrCode`, { method: 'POST', data });
}

/** 获取用户可选角色 */
export async function getSchAdminChooseRole(data: any) {
  return request(`/${PROJECT_NAME}/schoolOrgAdmin/getSchAdminChooseRole`, { method: 'POST', data });
}

/** 更新所选角色信息 */
export async function updateSchUserToken(data: any) {
  return request(`/${PROJECT_NAME}/schoolOrgAdmin/updateSchUserToken`, { method: 'POST', data });
}

/** 是否能够切换角色 */
export async function checkChooseRole(data: any) {
  return request(`/${PROJECT_NAME}/schoolOrgAdmin/checkChooseRole`, { method: 'POST', data });
}